package com.project.web;

import com.project.pojo.Library;
import com.project.service.LibraryService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "AddServlet", value = "/AddServlet")
public class AddServlet extends HttpServlet {
    private LibraryService service = new LibraryService();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");

        String id = request.getParameter("id");
        String name = request.getParameter("name");
        String author = request.getParameter("author");
        String status = request.getParameter("status");
        String price = request.getParameter("price");

        Library library = new Library();
        library.setBookId(Integer.parseInt(id));
        library.setBookName(name);
        library.setBookAuthor(author);
        library.setBookStutas(Integer.parseInt(status));
        library.setBookPrice(Double.parseDouble(price));

        service.add(library);

        request.getRequestDispatcher("/SelectAll").forward(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
